package com.definesys.smecrailtransit.module.LinkPage.fragment;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.SmecManager.SmecRealm.RealmManager;
import com.definesys.smecrailtransit.SmecManager.SmecSession.SmecSession;
import com.definesys.smecrailtransit.base.SmecBaseFragment;
import com.definesys.smecrailtransit.databinding.LinkPageFragmentSixBinding;
import com.definesys.smecrailtransit.module.Login.bean.SmecUser;
import com.github.mzule.activityrouter.router.Routers;

/**
 * Created by cjy on 2018/1/23.
 */

public class LinkPageFragmentSix extends SmecBaseFragment {
    private LinkPageFragmentSixBinding linkPageFragmentSixBinding;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        linkPageFragmentSixBinding = DataBindingUtil.inflate(inflater, R.layout.link_page_fragment_six,container,false);

        linkPageFragmentSixBinding.start.setOnClickListener(v -> {
            RealmManager.getInstance().deleteRealmObject(SmecUser.class);
            RealmManager.getInstance().getRealm().beginTransaction();
            SmecSession.getSmecUser().setLastLogin(true);
            SmecSession.getSmecUser().setLinkpage(false);
            RealmManager.getInstance().getRealm().commitTransaction();
            RealmManager.getInstance().insert(SmecSession.getSmecUser());

            Routers.open(linkPageFragmentSixBinding.getRoot().getContext(),"smec://LoginActivity");
        });

        return linkPageFragmentSixBinding.getRoot();
    }

    @Override
    protected Object getPersenter() {
        return null;
    }


    public static LinkPageFragmentSix newInstance(){
        Bundle args = new Bundle();
        LinkPageFragmentSix fragment = new LinkPageFragmentSix();
        fragment.setArguments(args);
        return fragment;
    }
}
